home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / mac / hypercar / mactool / thinkcgu.sit / TC Prog Guide / card_36058.txt < prev    next >
Encoding:
Text File  |  1991-02-27  |  1.2 KB  |  30 lines

  1. -- card: 36058 from stack: in
  2. -- bmap block id: 0
  3. -- flags: 0000
  4. -- background id: 4755
  5. -- name: 
  6.  
  7.  
  8. -- part contents for background part 6
  9. ----- text -----
  10. 4.1  Classes & Methods
  11.  
  12. -- part contents for background part 4
  13. ----- text -----
  14. TC supports OOP simply by extending the existing 'struct' user-defined type available in C.  The definition of a user-defined struct type is said to be a CLASS definition if function prototype declarations are included as members of the struct.  In this case, the members which are variable declarations are said to declare INSTANCE VARIABLES and the "member function" declarations are said to declare the METHODS which apply to these variables.  The following defines the Person class, which declares age and weight instance variables, and set() and print() methods:
  15.  
  16.     struct Person:indirect    /* in C++ omit ':indirect' */
  17.     {
  18.         int       age;
  19.         int       weight;
  20.  
  21.         void    set(void);         /* in C++ use 'virtual void set(void)' */
  22.         void    print(void);    /* in C++ use 'virtual void print(void)' */
  23.     };
  24.  
  25. (A useful convention is to begin all class names with a capital letter.)
  26.  
  27.  
  28. -- part contents for background part 7
  29. ----- text -----
  30. 106